/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.apache.skywalking.oap.server.core.storage.model;

import java.util.List;
import lombok.Getter;
import org.apache.skywalking.oap.server.core.analysis.Downsampling;

/**
 * @author peng-yongsheng
 */
@Getter
public class Model {

    // 以 ES 为例

    // Metric 名称，在 OAP 创建 ES 索引时会使用
    private final String name;
    // 对应 ES 索引中存储的数据是否为时间相关的数据
    private final boolean capableOfTimeSeries;
    // 如果是时间相关的数据，则需要指定其 Downsampling 单位，可选值有 Second、 Minute、 Hour、 Day、 Month。对于非时间相关的数据，则该字段值为 Downsampling.NONE。
    private final Downsampling downsampling;
    // 是否删除历史数据
    private final boolean deleteHistory;
    // ES 索引 中的 Field 集合，一个 ModelColumn 对象记录了一个 Field 的名称、类型等信息。
    // 《column集合与Field的映射关系.png》
    private final List<ModelColumn> columns;
    // 对应指标的全局唯一 ID
    private final int scopeId;

    public Model(String name, List<ModelColumn> columns, boolean capableOfTimeSeries, boolean deleteHistory, int scopeId, Downsampling downsampling) {
        this.columns = columns;
        this.capableOfTimeSeries = capableOfTimeSeries;
        this.downsampling = downsampling;
        this.deleteHistory = deleteHistory;
        this.scopeId = scopeId;
        // ES 索引的名称由三部分构成：Metric 名称、DownSampling、时间窗口（后面两部分只有时序数据才会有），而 ES 索引的别名由 Metric 名称和 DownSampling 构成。
        // ES 索引的别名由 Metric 名称和 DownSampling 构成。
        this.name = ModelName.build(downsampling, name);
    }
}
